# 每个学生的兴趣，统计兴趣爱好最多的几项
like_count = {}


def get_favorite():
    with open("021.txt", "r", encoding="utf-8") as file:
        for line in file:
            line = line[:-1]
            name, likes = line.split(" ")
            likes_list = likes.split(",")
            for like in likes_list:
                if like not in like_count:
                    like_count[like] = 1
                else:
                    like_count[like] += 1
    return like_count


a = get_favorite()
print(a)
sorted_a = sorted(a.items(), key=lambda x: x[1], reverse=True)
print(sorted_a)
